<?php
/*
* Created on Nov 4, 2007
*
* Continut:
*
*/
include("../include/classes/form.php");

function showCenterSectionElements(){
	if(isset($_GET['gcenter'])){
		switch ($_GET['gcenter']){
			case 'login':
				showLoginForm();
				break;

			case 'register':
				showRegisterForm();
				break;
			
			case 'forgotpass':
				showForgotPassForm();
				break;
		}
	}else {
		showIndexPage();
	}
}

function showIndexPage(){
	echo("<br />");
	echo("<div class='paragraph'>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Praesent placerat arcu nec est. Vivamus lacus. Aliquam et risus. Morbi hendrerit sollicitudin purus. Mauris ac tellus vitae libero pharetra luctus. Nunc interdum porta massa. Suspendisse bibendum, ipsum vitae ornare eleifend, lacus felis convallis mauris, et porttitor turpis augue eget mi. Sed purus diam, bibendum in, tempus adipiscing, ultricies eget, lectus. Cras cursus, enim vitae facilisis interdum, leo nibh iaculis nulla, quis aliquam est tellus quis lectus. Curabitur laoreet. Duis blandit. Etiam in tortor.</div>");
	echo("<div class='paragraph'>Sed pharetra blandit lectus. Pellentesque fringilla. Fusce rutrum aliquet purus. Proin ac lacus sed enim nonummy placerat. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Nunc posuere metus ac ipsum. Nulla mattis tellus a ipsum fringilla fringilla. In sed eros vitae tellus laoreet dignissim. Etiam porttitor, nunc nec porttitor ornare, turpis libero dictum odio, ut nonummy erat neque non ante. Suspendisse potenti. Aenean eleifend pretium eros. Suspendisse nec magna eu nisi egestas pulvinar. Quisque mauris. Donec tincidunt. Nunc eu enim vitae purus pretium tincidunt.</div>");
	echo("<div class='paragraph'>Cras lacus pede, luctus vel, tincidunt ac, mollis et, nulla. Nunc iaculis, purus a cursus posuere, arcu pede ultricies nisl, non dignissim pede nunc convallis mauris. Fusce lectus. Sed enim risus, varius eu, aliquam sed, eleifend ut, massa. Vestibulum feugiat. Suspendisse potenti. Suspendisse urna. Vivamus semper sodales odio. Pellentesque rutrum velit nec tellus. Phasellus bibendum, est tristique iaculis ornare, lectus dui ornare justo, eu tempor pede tortor laoreet mi. Vivamus a elit nec nisl condimentum porta. Nunc lacinia metus eget leo. Ut eget pede. Etiam euismod arcu ac lectus. Etiam iaculis sapien vitae diam. Duis ullamcorper, mauris ac suscipit pretium, nisl purus ultricies magna, non scelerisque augue felis quis nisl. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Morbi blandit adipiscing velit. Nulla aliquet justo et lectus. Fusce at magna in metus rutrum dignissim.</div>");
}

function showLoginForm(){
	$form=new Form();
	echo("<form action='process.php' method='POST'>");
    echo("<table align='center' border='0' bordercolor='#000000' id='meniuStanga'>");
    
    echo("<tr><td>Utilizator :</td>");
    echo("<td><input size='20' type='text' name='user' maxlength='30' value='".$form->value('user')."'></td></tr>");
    echo("<tr><td colspan='2' align='center'>".$form->error('user')."</td></tr>");

    echo("<tr><td>Parola :</td>");
    echo("<td><input size='20' type='password' name='pass' maxlength='30' value='".$form->value('pass')."'></td></tr>");
    echo("<tr><td colspan='2' align='center'>".$form->error('pass')."</td></tr>");

    echo("<tr><td colspan='2' align = 'center'><input type = 'checkbox' name = 'remember'");    
    if($form->value('remember') != ''){ 
    	echo "checked>"; 
    }
    echo("<font size='2'>Retine parola<input type='hidden' name='sublogin' value='1'></td></tr>");

    echo("<tr><td colspan='2' align='center'><input type='submit' value='Login'></td></tr>");
    echo("<tr><td colspan='2' align='center'><font size='2'>");
    echo("<a href='index.php?gcenter=forgotpass'>Ai uitat parola?</a></font></td></tr>");
    echo("</table></form>");
}

function showRegisterForm(){
	global $currentSession;
	$form=new Form();
	if(isset($_SESSION['regsuccess'])){
		//succes la inregistrare
		if($_SESSION['regsuccess']){
			echo "<h1 align='center'>Ai fost integistrat !</h1>";
			echo "<p align='center'>Multumim <b>" . $_SESSION['reguname']. "</b>, datele tale au fost adaugate in baza de date, acum te poti <a href='index.php?gcenter=login'>loga</a></p>";
		}else{ //esec la inregistrare
			echo "<h1 align='center'>Inregistrarea a esuat</h1>";
			echo "<p align='center'>Ne pare rau, dar o eroare a aparut si inregistrarea pentru utilizatorul<b>". $_SESSION['reguname'] . "</b>, nu a fost realizata.<br>Va rugam incercati mai tarziu.</p>";
		}
		unset($_SESSION['regsuccess']);
		unset($_SESSION['reguname']);
	}else{//afisare form inregistrare
		echo ("<br><br>");
		echo("<form action='process.php' method='POST'>");
		$tab="";
		echo("<table align='center' width='80%' border='0' id='anunt'>");
		echo("<input type='hidden' name='subjoin' value='1'>");
		if($form->error("reguser")==""){
			$tab="";
		}else{
			$tab="<br>";
		}
		echo ("<tr><td align='center'>Nume utilizator:</td><td align='center'>".$form->error("reguser").$tab."<input type='text' name='reguser' maxlength='30' value='".$form->value("reguser")."'></td></tr>");
		if($form->error("regpass")==""){
			$tab="";
		}else{
			$tab="<br>";
		}
		echo ("<tr><td align='center'>Parola:</td><td align='center'>".$form->error("regpass").$tab."<input type='password' name='regpass' maxlength='30' value='".$form->value("regpass")."'></td></tr>");
		if($form->error("regemail")==""){
			$tab="";
		}else{
			$tab="<br>";
		}
		echo ("<tr><td align='center'>Email:</td><td align='center'>".$form->error("regemail")."$tab<input type='text' name='regemail' maxlength='50' value='".$form->value("regemail")."'></td></tr>");
		echo ("<tr><td colspan='2' align='center'><input type='submit' value='Inregistrare!'></td></tr>");
		echo ("</table></form>");
	}
}

function showForgotPassForm(){
	//global $form,$session, $LANG;
	$form=new Form();
	//formularul a fost trimis si userul se afla in bd
	if (isset($_SESSION['forgotpass']))
	{

		//s-a generat o noua parola si a fost trimisa la adresa de mail
		if ($_SESSION['forgotpass'])
		{
			echo "<h1 align='center'>Parola a fost generata</h1>";
			echo "<p align='center'>O noua parola ti-a fost generata si trimisa la adreasa de email <br>asociata contului tau,</p>";
		}
		//mailul nu a putut fi trimis, parola nu a fost modificata in bd
		else
		{
			echo "<h1 align='center'>Eroare generare parola noua</h1>";
			echo "<p align='center'>O eroare a aparut la trimiterea noii tale parole la adresa ta de email; <br>in consecinta vechea parola nu a fost modificata</p>";
		}
		unset ($_SESSION['forgotpass']);
	}

	//facem afisarea formularului si eventualelor erori
	else
	{
		echo ("<table width='600' border='0' bordercolor='#000000' align='center'>");
		echo ("<tr ><td width='90'>&nbsp;</td>");
		echo ("<td align='center'>Ai uitat parola ?</td><td width='57'>&nbsp;</td></tr>");
		echo ("<tr><td rowspan='3'>&nbsp;</td>");
		echo ("<td width='431' align='center'>O noua parola iti va fi generata si trimisa la adresa de email asociata contului tau, tot ce trebuie sa faci e sa-ti introduci numele de utilizator.</td>");
		echo ("<td rowspan='3'>&nbsp;</td></tr>");
		echo ("<tr><td align='center'>");
		echo ($form->error("usernewpass") . "<br>");
		echo ("<form action='process.php' method='POST'><b>Utilizator :</b> <input type='text' name='usernewpass' maxlength='30' value='" . $form->value("usernewpass"). "'><input type='hidden' name='subforgot' value='1'>");
		echo ("</td></tr>");
		echo ("<tr><td align='center'><input type='submit' value='Genereaza parola noua'></form></td></tr>");
		echo ("</table>");
	}

}

echo("<td  id='pageContent'>");
showCenterSectionElements();
//echo("*************");
//var_dump($_SESSION['value_array']);
//echo("*************");
//var_dump($_SESSION['error_array']);
echo("</td></tr>");
?>
